define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'news/message/index' + location.search,
                    // add_url: 'news/message/add',
                    edit_url: 'news/message/edit',
                    del_url: 'news/message/del',
                    // multi_url: 'news/message/multi',
                    // import_url: 'news/message/import',
                    table: 'message',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                escape:false,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'messagetype.name', title: __('Type'), operate: false},
                        {field: 'title', title: __('Title'), operate: false},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'personal.account', title: __('Uid')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __("Status"), operate: 'LIKE',searchList: {"0":__('未回复'),"1":__('已回复')}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        // {field: 'contact_way', title: __("联系类型"), operate: 'LIKE',searchList: {"1":__('手机'),"2":__('QQ')}, formatter: Table.api.formatter.label},
                        {field: 'contact_code', title: __("联系手机"), operate: false},
                        // {field: 'reply_content', title: __('回复内容'), operate: false,
                        //             cellStyle:function (value, row, index) {
                        //                 return {
                        //                     css: {
                        //                         "min-width": "100px",
                        //                         "white-space": "nowrap",
                        //                         "text-overflow": "ellipsis",
                        //                         "overflow": "hidden",
                        //                         "max-width": "240px",
                        //                         "cursor": "pointer"
                        //                     }
                        //                 }
                        //             },
                        // },
                        {field: 'replytime', title: __('Replytime'), operate: false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
